package com.workflow.action;

import java.util.List;

import com.base.bean.Cardinfo;
import com.base.service.CardinfoService;
import com.base.service.DictService;
import com.common.bean.Datadict;
import com.common.bean.Personnel;
import com.common.util.PagerModel;
import com.common.util.StringToken;
import com.core.ssh2.AbstractActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.workflow.bean.Outputdeptdetail;
import com.workflow.service.OutputcardService;
import com.workflow.service.OutputdeptdetailService;

public class OutputcardManagerAction extends AbstractActionSupport implements
		Preparable {
	private static final long serialVersionUID = -6502967542131229744L;

	private OutputcardService outputcardService;
	
	private CardinfoService cardinfoService;
	
	private OutputdeptdetailService outputdeptdetailService;
	
	private DictService dictService;
	
	private Outputdeptdetail outputdeptdetail;
	
	private Cardinfo cardinfo;
	
	private String outdetailno;
	
	private String cardno;
	
	private PagerModel pm;
	
	private List<Datadict> datadictByBasetypelist;
	
	private List<Datadict> datadictByAreatypelist;
	
	private List<Datadict> datadictByFuntypelist;
	
	private Datadict datadictByBasetype;

	private Datadict datadictByAreatype;

	private Datadict datadictByFuntype;
	
	private long money;//面额
	
	private boolean selected;//是否是查看已选卡标识
	
	private long num;
	
	@SuppressWarnings("unchecked")
	public void prepare() throws Exception {
		//字典选项
		datadictByBasetypelist = dictService.findDictDetail(StringToken.DICT_CARD_BASETYPE);
		datadictByAreatypelist = dictService.findDictDetail(StringToken.DICT_CARD_AREATYPE);
		datadictByFuntypelist = dictService.findDictDetail(StringToken.DICT_CARD_FUNTYPE);
//		num = outputcardService.findAllOutputcardByOutdetailno(outdetailno).size();//没有用
	}
	
	@Override
	public String execute() throws Exception {
		outputdeptdetail = outputdeptdetailService.findOutputdeptdetail(outdetailno);
		return SUCCESS;
	}
	
	public String addOutputcard() throws Exception {
		outputcardService.addOutputcard(cardno, outdetailno);
		return SUCCESS;
	}
	
	public String findCardinfoForOutdetailno() throws Exception {
		Personnel personnel = (Personnel) this.getSession().get(StringToken.CURRENT_LOGIN);
		selected = false;
		outputdeptdetail = outputdeptdetailService.findOutputdeptdetail(outdetailno);
		//根据三种类型、面额,子卡类型（志号）选卡（状态为已入库，切所属部门为当前登录用户所属部门） 
		pm = cardinfoService.findCardinfoForPagerWith(datadictByBasetype.getTypeid(), 
				datadictByAreatype.getTypeid(), datadictByFuntype.getTypeid(),
				StringToken.DICT_CARDSTATUS_STORE, money,
				outputdeptdetail.getCardsubtype().getCardsubtypeno(),personnel.getDepartment().getDeptcode());
		return SUCCESS;
	}
	
	public String findCardinfoOutputSelected() throws Exception {
		Personnel personnel = (Personnel) this.getSession().get(StringToken.CURRENT_LOGIN);
		selected = true;
		outputdeptdetail = outputdeptdetailService.findOutputdeptdetail(outdetailno);
//		根据出库明细号（状态为流转）当前部门(出库单所属部门) 子卡类型 
		pm = cardinfoService.findCardinfoForPagerWithBelongto(outdetailno, StringToken.DICT_CARDSTATUS_LOCK,
				outputdeptdetail.getCardsubtype().getCardsubtypeno(),personnel.getDepartment().getDeptcode());
		return SUCCESS;
	}
	
	public String delOutputcard() throws Exception {//outdetailno存在且需要传递
		outputcardService.removeOutputcard(cardno);//修改卡状态，卡信息所属 跳转到已选卡列表
		return SUCCESS;
	}

	/**
	 * @return the cardinfo
	 */
	public Cardinfo getCardinfo() {
		return cardinfo;
	}

	/**
	 * @param cardinfo the cardinfo to set
	 */
	public void setCardinfo(Cardinfo cardinfo) {
		this.cardinfo = cardinfo;
	}

	/**
	 * @return the cardinfoService
	 */
	public CardinfoService getCardinfoService() {
		return cardinfoService;
	}

	/**
	 * @param cardinfoService the cardinfoService to set
	 */
	public void setCardinfoService(CardinfoService cardinfoService) {
		this.cardinfoService = cardinfoService;
	}

	/**
	 * @return the cardno
	 */
	public String getCardno() {
		return cardno;
	}

	/**
	 * @param cardno the cardno to set
	 */
	public void setCardno(String cardno) {
		this.cardno = cardno;
	}

	/**
	 * @return the datadictByAreatype
	 */
	public Datadict getDatadictByAreatype() {
		return datadictByAreatype;
	}

	/**
	 * @param datadictByAreatype the datadictByAreatype to set
	 */
	public void setDatadictByAreatype(Datadict datadictByAreatype) {
		this.datadictByAreatype = datadictByAreatype;
	}

	/**
	 * @return the datadictByAreatypelist
	 */
	public List<Datadict> getDatadictByAreatypelist() {
		return datadictByAreatypelist;
	}

	/**
	 * @param datadictByAreatypelist the datadictByAreatypelist to set
	 */
	public void setDatadictByAreatypelist(List<Datadict> datadictByAreatypelist) {
		this.datadictByAreatypelist = datadictByAreatypelist;
	}

	/**
	 * @return the datadictByBasetype
	 */
	public Datadict getDatadictByBasetype() {
		return datadictByBasetype;
	}

	/**
	 * @param datadictByBasetype the datadictByBasetype to set
	 */
	public void setDatadictByBasetype(Datadict datadictByBasetype) {
		this.datadictByBasetype = datadictByBasetype;
	}

	/**
	 * @return the datadictByBasetypelist
	 */
	public List<Datadict> getDatadictByBasetypelist() {
		return datadictByBasetypelist;
	}

	/**
	 * @param datadictByBasetypelist the datadictByBasetypelist to set
	 */
	public void setDatadictByBasetypelist(List<Datadict> datadictByBasetypelist) {
		this.datadictByBasetypelist = datadictByBasetypelist;
	}

	/**
	 * @return the datadictByFuntype
	 */
	public Datadict getDatadictByFuntype() {
		return datadictByFuntype;
	}

	/**
	 * @param datadictByFuntype the datadictByFuntype to set
	 */
	public void setDatadictByFuntype(Datadict datadictByFuntype) {
		this.datadictByFuntype = datadictByFuntype;
	}

	/**
	 * @return the datadictByFuntypelist
	 */
	public List<Datadict> getDatadictByFuntypelist() {
		return datadictByFuntypelist;
	}

	/**
	 * @param datadictByFuntypelist the datadictByFuntypelist to set
	 */
	public void setDatadictByFuntypelist(List<Datadict> datadictByFuntypelist) {
		this.datadictByFuntypelist = datadictByFuntypelist;
	}

	/**
	 * @return the dictService
	 */
	public DictService getDictService() {
		return dictService;
	}

	/**
	 * @param dictService the dictService to set
	 */
	public void setDictService(DictService dictService) {
		this.dictService = dictService;
	}

	/**
	 * @return the money
	 */
	public long getMoney() {
		return money;
	}

	/**
	 * @param money the money to set
	 */
	public void setMoney(long money) {
		this.money = money;
	}

	/**
	 * @return the num
	 */
	public long getNum() {
		return num;
	}

	/**
	 * @param num the num to set
	 */
	public void setNum(long num) {
		this.num = num;
	}

	/**
	 * @return the outdetailno
	 */
	public String getOutdetailno() {
		return outdetailno;
	}

	/**
	 * @param outdetailno the outdetailno to set
	 */
	public void setOutdetailno(String outdetailno) {
		this.outdetailno = outdetailno;
	}

	/**
	 * @return the outputcardService
	 */
	public OutputcardService getOutputcardService() {
		return outputcardService;
	}

	/**
	 * @param outputcardService the outputcardService to set
	 */
	public void setOutputcardService(OutputcardService outputcardService) {
		this.outputcardService = outputcardService;
	}

	/**
	 * @return the outputdeptdetail
	 */
	public Outputdeptdetail getOutputdeptdetail() {
		return outputdeptdetail;
	}

	/**
	 * @param outputdeptdetail the outputdeptdetail to set
	 */
	public void setOutputdeptdetail(Outputdeptdetail outputdeptdetail) {
		this.outputdeptdetail = outputdeptdetail;
	}

	/**
	 * @return the outputdeptdetailService
	 */
	public OutputdeptdetailService getOutputdeptdetailService() {
		return outputdeptdetailService;
	}

	/**
	 * @param outputdeptdetailService the outputdeptdetailService to set
	 */
	public void setOutputdeptdetailService(
			OutputdeptdetailService outputdeptdetailService) {
		this.outputdeptdetailService = outputdeptdetailService;
	}

	/**
	 * @return the pm
	 */
	public PagerModel getPm() {
		return pm;
	}

	/**
	 * @param pm the pm to set
	 */
	public void setPm(PagerModel pm) {
		this.pm = pm;
	}

	/**
	 * @return the selected
	 */
	public boolean isSelected() {
		return selected;
	}

	/**
	 * @param selected the selected to set
	 */
	public void setSelected(boolean selected) {
		this.selected = selected;
	}

}
